<template>
    <view class="content">
        <view class="title text-lg">盘点信息</view>
        <view class="box text-noraml">
            <view class="item text-bold">{{category}}</view>
            <view class="item">
                <view>盘点人</view>
                <view class="item-r text-bold">{{member}}</view>
            </view>
            <view class="item">
                <view>盘点时间</view>
                <view class="item-r text-bold">{{pdate}}</view>
            </view>
        </view>
        
        <view class="title text-lg">盘点物品</view>
        <view class="wrapper">
            <view class="drug text-df text-gray" v-for="(item, index) in list" :key="index">
                <view>物品名称：{{item.goods_name}}</view>
                <view class="u-p-t-15">批次号：{{item.batch}}</view>
                <view class="u-p-t-15">规格：{{item.goods_spec}}</view>
                <view class="u-p-t-15">有效日期：{{item.period_date}}</view>
                <view class="u-p-t-15">生产厂家：{{item.factory}}</view>
                <view class="u-p-t-15">供货厂家：{{item.supplier}}</view>
                <view class="u-p-t-15" v-if="item.stock_nums">实际库存数量：{{ item.stock_nums }}</view>
                <view class="u-p-t-15" v-if="item.produce_date">生产日期：{{ item.produce_date }}</view>
                <view class="u-p-t-15" v-if="item.scaler_num">包装：{{ item.scaler_num }}</view>
                
                <template v-if="fromRecord">
                    <view class="u-p-t-15">库存量：{{item.stock_nums}}</view>
                    <view class="u-p-t-15">盘点数量：{{item.nums}}</view>
                    <view class="u-p-t-15">盘盈盘亏数量：{{item.lack_nums}}</view>
                    <view class="u-p-t-15">盘点状态：{{item.order_status_txt}}</view>
                </template>
                
                <view class="u-flex u-p-t-15" v-if="!fromRecord">
                    <!-- status=1是盘点完，0-是未盘点 -->
                    <view v-if="item.status == 1">盘点数量：{{item.nums}}</view>
                    <view class="u-flex" v-if="item.status == 0">
                        盘点数量：<input type="number" v-model="item.pd_num" placeholder="请输入" class="inp">
                    </view>
                    <view class="drug-btn" v-if="item.status == 0" @click="doSubmit(item)">提交</view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                plan_id: '',//计划id
                id: '',//子计划id
                list: [],
                fromRecord: '',//1 从盘点记录进入
                type: 0,
                category: '',
                member: '',
                pdate: '',
            };
        },
        onLoad(option) {
            if (option.fromRecord) {
                this.fromRecord = option.fromRecord
                this.type = 1
            }
            if (option.category) {
                this.category = option.category
                this.member = option.member
                this.pdate = option.pdate
            }
            this.id = option.id
            this.plan_id = option.plan_id
            this.getData()
        },
        methods: {
            doSubmit(item) {
                if (item.pd_num < 1) {
                    this.$toast('盘点数量最小是1');
                    return
                }
                this.$ajax('inventorys/plan', {
                    userToken: this.$getSync('userToken'),
                    id: item.id,//盘点 记录编号
                    nums: item.pd_num, //盘点数量
                }).then(ret => {
                	if (ret.status == 0) {
                        this.$toast('提交成功');
                        setTimeout(() => {
                            this.getData()
                        }, 500)
                	} else {
                		this.$toast(ret.message);
                	}
                });
            },
            
            // 获取盘点计划详情--盘点物品
            getData() {
            	this.$ajax('inventorys/plan_goods_list', {
                    userToken: this.$getSync('userToken'),
                    plan_id: this.plan_id,
                    sub_plan_id: this.id,
                    type: this.type, //0-盘点计划商品 1-盘点 记录
                    // page: 1,
                    // limit: 9999,
                }).then(ret => {
            		if (ret.status == 0) {
                        this.list = ret.data
                        if (this.list && this.list.length > 0) {
                            // status=1是盘点完，0-是未盘点
                            this.list.forEach(cur => {
                                if (cur.status == 0 && !cur.pd_num) {
                                    this.$set(cur, 'pd_num', '')
                                } 
                            })
                        } 
            		} else {
            			this.$toast(ret.message);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    .inp{
        flex: 1;
        height: 60rpx;
        line-height: 60rpx;
        padding: 0 20rpx;
        background-color: #f5f5f5;
        border-radius: 10rpx;
        color: #000;
    }
    
    page{
        background-color: #f5f5f5 !important;
    }
    .title{
        font-weight: bold;
        padding: 45rpx 50rpx 25rpx;
        position: relative;
    }
    .title::after{
        display: block;
        content: '';
        width: 8rpx;
        height: 26rpx;
        background-color: #ff4800;
        position: absolute;
        left: 25rpx;
        bottom: 32rpx;
    }
    
    
    .box{
        padding: 0 30rpx;
        background-color: #fff;
    }
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 30rpx 0;
        border-bottom: 2rpx solid #e6e6e6;
    }
    .item:last-child{
        border-bottom: none;
    }
    .item-r{
        flex: 1;
        word-break: break-all;
        white-space: pre-line;
        text-align: right;
        padding-left: 20rpx;
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }
    .item-img{
        padding: 30rpx 0;
    }
    .img{
        width: 316rpx;
        height: 200rpx;
        border-radius: 10rpx;
        margin-top: 20rpx;
    }
    
    
    .drug{
        background-color: #fff;
        border-radius: 15rpx;
        padding: 35rpx 30rpx;
        margin-bottom: 25rpx;
        word-break: break-all;
        white-space: pre-line;
    }
    .drug:last-child{
        margin-bottom: 0;
    }
    .drug-state1{
        font-size: 24rpx;
        color: #0075ff;
        padding: 9rpx 12rpx;
        background-color: #ebf4fe;
        border-radius: 8rpx;
        margin-left: 20rpx;
    }
    
    
    .examine{
        word-break: break-all;
        white-space: pre-line;
        padding: 15rpx 25rpx 30rpx;
        background-color: #fff;
        border-radius: 15rpx;
        margin: 0 30rpx 25rpx;
    }
    .t-inp{
        width: 100%;
        min-height: 150rpx;
        height: auto;
        padding-top: 15rpx;
    }
    .examine2{
        padding: 15rpx 0;
    }
    .img-box{
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-start;
        align-items: center;
    }
    .up-photo{
        width: 187rpx;
        height: 187rpx;
        margin-right: 15rpx;
        margin-top: 15rpx;
    }
    
    
    .btns{
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin: 30rpx;
    }
    .refuse-btn{
        font-size: 34rpx;
        color: #757575;
        padding: 25rpx 130rpx;
        background-color: #fff;
        border: 2rpx solid #d8d8d8;
        border-radius: 10rpx;
    }
    .take-btn{
        font-size: 34rpx;
        color: #fff;
        padding: 25rpx 130rpx;
        background-color: #ff4800;
        border-radius: 10rpx;
        margin-left: 20rpx;
    }
    
    .enter-btn{
        display: flex;
        justify-content: flex-end;
        align-items: center;
        padding-top: 10rpx;
    }
    .enter-btn>view{
        padding: 15rpx 50rpx;
        background-color: #8392a5;
        border-radius: 10rpx;
        color: #fff;
    }
    
    .place{
        word-break: break-all;
        white-space: pre-line;
        padding: 5rpx 20rpx 20rpx;
        background-color: #f5f6f8;
        border-radius: 10rpx;
        margin-top: 30rpx;
    }
    .wrapper{
        padding: 0 30rpx;
    }
    .choose-01{
        width: 33rpx;
        height: 33rpx;
        margin-right: 15rpx;
    }
    .time-02{
        width: 33rpx;
        height: 34rpx;
        margin-left: 15rpx;
    }
    
    .drug-btn{
        color: #fff;
        padding: 10rpx 30rpx;
        background-color: #8392a5;
        border-radius: 8rpx;
        margin-left: 20rpx;
    }

</style>
